<template>
	<view class="content">
		<uni-section title="精选圈子" type="line">
			<view class="circle">
				<view class="circle-item" hover-class="circle-item-hover"
					@click="handleCircleClick(item.id,item.circleName)" v-for="item in props.circleList" :key="item.id">
					<image class="icon" :src="item.circleAvatar"></image>
					<text class="text">{{ formatCircleName(item.circleName) }}</text>
				</view>
			</view>
		</uni-section>
	</view>
</template>

<script setup lang="ts">
	import { ref, onMounted, defineExpose, defineProps } from 'vue';
	import type { CircleBasicInfo } from '@/api/circle/circle';
	import { getHotCircle } from '@/api/circle/circle';

	// 定义props
	const props = defineProps<{
		circleList : CircleBasicInfo[]
	}>()

	// 处理圈子点击事件
	const handleCircleClick = (id : number) => {
		// 直接跳转到圈子详情页面，只传递圈子ID
		uni.navigateTo({
			url: `/pages/circle/circleDetail/circleDetail?id=${id}`
		})
	}

	// 格式化圈子名称，超6字显示前5字+...
	const formatCircleName = (name: string) => {
	  if (!name) return '';
	  return name.length > 6 ? name.slice(0, 5) + '...' : name;
	};
</script>

<style lang="scss">
	.content {
		margin: 20rpx 20rpx;
		padding: 15rpx 0;
		background-color: #FFFFFF;
		border-radius: 5%;
		min-height: 328rpx;
		justify-content: center;
		flex-direction: column;
		align-items: center;
		// 添加阴影效果
		box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);

		.circle {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-around;

			.circle-item {
				width: 25%;
				display: flex;
				justify-content: center;
				flex-direction: column;
				align-items: center;
				box-sizing: border-box;
				transition: all 0.3s ease; // 添加过渡动画

				.icon {
					width: 80rpx;
					height: 80rpx;
					border-radius: 25%;
					transition: transform 0.3s ease; // 图标过渡动画
				}

				.text {
					font-size: 26rpx;
					color: #666;
					transition: color 0.3s ease; // 文字颜色过渡
				}
			}

			// 添加点击悬停样式
			.circle-item-hover {
				background-color: #f5f5f5; // 背景色变化
				border-radius: 10rpx; // 圆角
				transform: scale(0.95); // 轻微缩放效果

				.icon {
					transform: scale(1.1); // 图标放大
				}

				.text {
					color: #409EFF; // 文字颜色变为主题色
					font-weight: bold; // 文字加粗
				}
			}
		}
	}
</style>